package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.seapeak.recyclebundle.BaseHolder;
import com.seapeak.recyclebundle.BaseRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.databinding.AccumulatepointBinding;
import sz.szsmk.citizencard.model.network.bean.response.AccumPointRes;

/**
 * Created by hyt on 2019/4/26.
 */
public class AccumulatePointsListAdapter extends BaseRecyclerAdapter<AccumulatePointsListAdapter.AccumulatePointViewHolder>{
    private Context mContext;
    private List<AccumPointRes.CreditInfoBean> itemData;
    private int type;

    public AccumulatePointsListAdapter(Context context,int type){
        this.itemData = new ArrayList<>();
        this.mContext=context;
        this.type = type;
    }

    @Override
    public AccumulatePointViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return AccumulatePointViewHolder.creat(parent);
    }

    @Override
    public void onBindViewHolder(AccumulatePointViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        AccumPointRes.CreditInfoBean creditInfoBean = this.itemData.get(position);

        holder.binding.tvName.setText(creditInfoBean.getCreditTypeName());

        holder.binding.tvTime.setText(creditInfoBean.getGetTime());

        //1 积分获取 2 积分支出
        if(type==1){
            holder.binding.tvScore.setText("+"+creditInfoBean.getCredit());
        }else{
            holder.binding.tvScore.setText("-"+creditInfoBean.getCredit());
        }

    }

    @Override
    public int getItemCount() {
        return null == itemData ? 0 : itemData.size();
    }

    public void setItemData(List<AccumPointRes.CreditInfoBean> itemData) {
        this.itemData.addAll( itemData);
        notifyDataSetChanged();
    }

    public void cleanData(){
        itemData.clear();
        notifyDataSetChanged();
    }


    public static class AccumulatePointViewHolder extends BaseHolder {

        private AccumulatepointBinding binding;

        public static AccumulatePointViewHolder creat(ViewGroup parent) {

            AccumulatepointBinding binding = AccumulatepointBinding
                    .inflate(LayoutInflater.from((parent.getContext())), parent, false);
            return new AccumulatePointViewHolder(binding);
        }

        public AccumulatePointViewHolder(AccumulatepointBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
